import Mock from 'mockjs'

const List = []
const count = 100 


for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: '@increment',  
    role_name: '角色@integer(1, 100)', 
    role_menu: 'm_2,m_3',
    role_permissions: 'p_2_1,p_2_2,p_3_6'
  }))
}

export default [
  {
    url: '/project/system/sys_role/list',
    type: 'get',
    response: config => {
      const { importance, type, title, page = 1, limit = 20, sort } = config.query

      let mockList = List.filter(item => {
        if (importance && item.importance !== +importance) return false
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },

  {
    url: '/project/system/sys_role/detail',
    type: 'get',
    response: config => {
      const { id } = config.query
      for (const article of List) {
        if (article.id === +id) {
          return {
            code: 20000,
            data: article
          }
        }
      }
    }
  }, 

  {
    url: '/project/system/sys_role/create',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  {
    url: '/project/system/sys_role/update',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  {
    url: '/project/system/sys_role/menutreelist',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data:{
          items:[{
            label: '系统管理',
            id: 1,
            level: 0,
            code: 'm_1',
            children: [{
              label: '部门管理',
              id: 2,
              level: 1,
              code: 'm_2',
              permissions:[
                {name: '部门列表',value: 'p_2_1',id:1},
                {name: '添加部门',value: 'p_2_2',id:2},
                {name: '修改部门',value: 'p_2_3',id:3},
                {name: '删除部门',value: 'p_2_4',id:4},
              ]
            },{
              label: '角色管理',
              id: 3,
              level: 1,
              code: 'm_3',
              permissions:[
                {name: '角色列表',value: 'p_3_5',id:5},
                {name: '添加角色',value: 'p_3_6',id:6},
                {name: '修改角色',value: 'p_3_7',id:7},
                {name: '删除角色',value: 'p_3_8',id:8},
              ]
            }]
          }]
        }
      }
    }
  },
  
  {
    url: '/project/system/sys_role/updaterolemenu',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },
  
  {
    url: '/project/system/sys_role/updaterolepermission',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  {
    url: '/project/system/sys_role/delete',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]

